package com.wx.chat.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * webSocket的配置类
 * 启动webSocket的支持
 *
 * @Auther llh
 * @DateTime 2020-08-022
 */
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints( StompEndpointRegistry registry) {
        registry.addEndpoint("/ws")   //开启bulle端点
                .setAllowedOrigins ( "*" )     //允许跨域访问
                .withSockJS();                 //使用sockJs
    }

    @Override
    public void configureMessageBroker ( MessageBrokerRegistry registry ) {
        registry.setApplicationDestinationPrefixes ( "/app" );
        registry.enableSimpleBroker ( "/topic" );
    }
}
